from django.db import models


# Create your models here.
from courseapp.models import Course


class User(models.Model):
    # 用户名
    username = models.CharField(max_length=255)
    # 密码
    # 三方登录后绑定手机号后创建密码
    password = models.CharField(max_length=255,null=True)
    # 手机号
    phone = models.CharField(max_length=255,null=True)
    # 用户类型 0管理员，1普通用户，2会员，3超级会员，默认1
    type = models.IntegerField(default=1)
    # 何时加入实验楼
    create_time = models.DateTimeField(auto_now_add=True)
    # 会员开始时间——到底是用字符串字段好，还是用datetime好
    vip_start_time = models.CharField(max_length=255,null=True,default='')
    # 会员结束时间
    vip_end_time = models.CharField(max_length=255,null=True,default='')
    # 用户头像
    img = models.ImageField(null=True)
    # 用户邮箱
    email = models.EmailField(null=True)
    # 邀请码
    code = models.CharField(max_length=50,null=True)
    # 用户状态 学生/在职
    status = models.CharField(max_length=50,null=True)
    # 学校/公司
    where = models.CharField(max_length=50,null=True)
    # 会员积分 小数形式存放、最大九位数、精度为2
    points = models.DecimalField(max_digits=9, decimal_places=2,default=0,null=True)
    #是否激活
    is_active = models.IntegerField(default=0)
    # 用户课程多对多
    # course = models.ManyToManyField(to='Course',through='UsertoCourse',through_fields=('uid','course_id'))

    class Meta:
        db_table = 'user'


class Vip_Authority(models.Model):
    # 会员id
    uid = models.IntegerField()
    # 用户类型 0管理员，1普通用户，2会员，3超级会员，默认1
    type = models.IntegerField()
    # 免费课程
    free_course = models.BooleanField(default=0)
    # 会员课程
    vip_course = models.BooleanField(default=0)
    # 环境保存
    env_save = models.BooleanField(default=0)
    # 环境联网
    env_internet = models.BooleanField(default=0)
    # ssh
    ssh_use = models.BooleanField(default=0)
    # webIDE
    webIDE = models.BooleanField(default=0)
    # 折扣
    discount = models.FloatField()
    # 答疑
    answer = models.BooleanField(default=0)

    class Meta:
        db_table = 'vip_authority'

class SanFangUser(models.Model):
    #三方登录
    uid = models.IntegerField()
    app_type = models.CharField(max_length=255)
    access_token = models.CharField(max_length=255)
    access_user_info = models.CharField(max_length=255)

    class Meta:
        db_table = 'sanfang_Login'

class Coupons(models.Model):
    #优惠券表
    code = models.CharField(max_length=255)
    #优惠券描述
    desc = models.CharField(max_length=255)
    #优惠券类型
    coupons_type = models.IntegerField()

    class Meta:
        db_table = 'coupons'

class CouponstoUser(models.Model):
    code_id = models.IntegerField()
    uid = models.IntegerField()

    class Meta:
        db_table = 'coupons_to_user'

class UsertoCourse(models.Model):
    #用户课程表
    # uid = models.ForeignKey(to='User',on_delete=True)
    # course_id = models.ForeignKey(to='Course',on_delete=True)
    uid = models.IntegerField()
    course_id = models.IntegerField()

    class Meta:
        db_table = 'user_to_couse'

class UsertoPath(models.Model):
    #用户路径表
    uid = models.IntegerField()
    path_id = models.IntegerField()

    class Meta:
        db_table = 'user_to_path'

